Skip to content

Conversation

@chupe
Copy link
Collaborator

@chupe chupe commented Dec 18, 2025

PCSM-219 Powered by Pull Request Badge

Problem

Configuration handling was inconsistent across input sources. Environment variables, CLI flags, and HTTP request parameters lacked unified processing, making it difficult to reason about option precedence and validate inputs consistently. There were no integration tests for the CLI client subcommands.

Solution

Introduced Viper with mapstructure for unified configuration loading via a new config/ package with structured types (Config, MongoDBConfig, CloneConfig). Moved validation logic from main.go to config.Validate() for testability and consistent enforcement across all input sources.

Added CLI integration tests that build the binary once in TestMain and run it as a subprocess against a mock HTTP server. Tests cover all client subcommands (start, status, finalize, pause, resume) with their respective flags and verify port configuration via --port flag and PCSM_PORT env var.


Also added:

  • New CLI flags for MongoDB timeout and clone tuning options
  • Clone flags moved to start subcommand (per-operation design)
  • Complete configuration options reference table for QA/docs teams

An overview of how these changes affect the UX is summarized by @inelpandzic here as a post-hoc specification for the changes.

chupe added 13 commits December 23, 2025 20:18
- Add github.com/spf13/viper to go.mod
- Create config/config.go with Init() function
- Bind env vars for global options only (not clone tuning)

PCSM-219: Integrate Viper with Cobra for logging and server options

- Call config.Init() in PersistentPreRun
- Use Viper for log-level, log-json, no-color flags
- Use Viper for source/target URIs and port
- Simplify getPort() to use Viper with env var fallback
- Add --mongodb-cli-operation-timeout persistent flag (NOT hidden)
- Update MongoDBOperationTimeout() to use Viper
- Add deprecated alias OperationMongoDBCliTimeout() for backward compat
- Add --use-collection-bulk-write hidden persistent flag
- Update UseCollectionBulkWrite() to use Viper
- Env var PCSM_USE_COLLECTION_BULK_WRITE still supported
- Add --clone-num-parallel-collections hidden flag
- Add --clone-num-read-workers hidden flag
- Add --clone-num-insert-workers hidden flag
- Add --clone-segment-size hidden flag
- Add --clone-read-batch-size hidden flag
- All clone tuning options use Viper (CLI only, no env var support)
- Add github.com/go-playground/validator/v10 dependency
- Create validate/validate.go with singleton validator
- Create validate/errors.go with error types and translation
- Create validate/bytesize.go with custom byte size validators
- Extend pcsm.StartOptions with clone tuning fields
- Update startRequest with clone tuning fields and validation tags
- Add Validate() method to startRequest
- Add resolveStartOptions() to merge HTTP/CLI/config values
- Add resolveCloneSegmentSize/resolveCloneReadBatchSize helpers
- HTTP values take precedence over CLI values
- Add --mongodb-cli-operation-timeout to PCSM Options
- Update Environment Variables section with table format
- Add Clone Tuning Options section with CLI/HTTP parameters
- Update HTTP API /start with clone tuning parameters documentation
- Make --port a persistent flag (inherited by all subcommands)
- Remove duplicate port flag definitions from subcommands
- Simplify getPort() to use Viper directly (handles CLI > env var > default)
- Remove unused pflag import
- Add configuration reference table to config/config.go (single source of truth)
- Remove redundant config source comments from config/values.go
- Remove references to external decision documents
- Simplify function comments to describe behavior, not configuration
- Replace decision references with self-documenting comments
- Comments now describe what/why, not where it was decided
- Remove getPort() wrapper, use viper.GetInt("port") directly
- Remove unused GetString, GetInt, GetBool, IsSet wrappers from config/config.go
- These wrappers added no value (pure pass-through with no added logic)
PCSM-219: Update VSCode settings and README with additional config options

PCSM-219: Fix
@chupe chupe force-pushed the pcsm-219 branch 2 times, most recently from a6eb1af to 1721b17 Compare December 29, 2025 22:27
@chupe chupe marked this pull request as ready for review December 30, 2025 14:02
@chupe chupe requested a review from inelpandzic as a code owner December 30, 2025 14:02
@chupe chupe requested a review from inelpandzic December 30, 2025 16:53
inelpandzic and others added 3 commits December 31, 2025 06:40
- Add env var bindings: PCSM_PORT, PCSM_LOG_LEVEL, PCSM_LOG_JSON,
PCSM_NO_COLOR
- Remove --use-collection-bulk-write CLI flag (env var only)
- Hide clone-segment-size and clone-read-batch-size flags
- Remove help text from hidden flags
Copy link
Collaborator

@inelpandzic inelpandzic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left couple of comments, please check them out, but overall I'm really really happy how this turned out!

@chupe chupe requested a review from inelpandzic January 7, 2026 16:17
@chupe chupe requested a review from inelpandzic January 8, 2026 11:43
@chupe chupe merged commit 54840e7 into main Jan 8, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants